//
//  MyInfoController.m
//  i5db
//
//  Created by iMuse on 15-5-12.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "MyInfoController.h"
#import "AppCenter.h"
#import "AppButtonView.h"
#import "APPTextController.h"
#import "AppSexView.h"
#define HeaderTitleFontColor       @"255,255,255,1"

@interface MyInfoController ()<onButtonDelegate,textViewDelegate,selectSexDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    
    UIButton    * headView;
    UIImageView * imageView;
}

@end

@implementation MyInfoController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
                self.title = @"我的信息";
    }
    return self;
}
-(void)updateViewConstraints
{
    [super updateViewConstraints];
    [headView autoPinToTopLayoutGuideOfViewController:self withInset:10];
    [headView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [headView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [headView autoSetDimension:ALDimensionHeight toSize:60];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setNeedsUpdateConstraints];

    [self initNavigationBar];
    [self initView];
}
-(void)initNavigationBar
{
    [super initNavigationBar];

   
    
    
}
-(void)goBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void) initView
{
    headView = [UIButton newAutoLayoutView];
    [headView addTarget:self action:@selector(selectImage:) forControlEvents:UIControlEventTouchUpInside];
    headView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:headView];
    
    UILabel* headLabel = [UILabel newAutoLayoutView];
    headLabel.font = [UIFont systemFontOfSize:13];
    headLabel.text     = @"头像";
    [headView addSubview:headLabel];
    [headLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [headLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
    [headLabel autoSetDimension:ALDimensionWidth toSize:40];
    [headLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:10];
  
    imageView = [UIImageView newAutoLayoutView];
    imageView.image = [UIImage imageNamed:@"NoHeaderImge@2x"];
    [headView addSubview:imageView];
    [imageView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:5];
    [imageView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
    [imageView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:5];
    [imageView autoSetDimension:ALDimensionWidth toSize:50];
    
    
    AppButtonView* nameView = [AppButtonView newAutoLayoutView];
    [self.view addSubview:nameView];
    nameView.delegate = self;
    nameView.tag = 1;
    [nameView setLeftText:@"姓名"];
    [nameView setRightText:@"王国栋"];
    [nameView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:headView withOffset:15];
    [nameView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [nameView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [nameView autoSetDimension:ALDimensionHeight toSize:40];
    
    AppButtonView* sexView = [AppButtonView newAutoLayoutView];
    sexView.tag             = 2;
    sexView.delegate        = self;
    [self.view addSubview:sexView];
    [sexView setLeftText:@"性别"];
    [sexView setRightText:@"男"];
    [sexView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:nameView withOffset:0];
    [sexView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [sexView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [sexView autoSetDimension:ALDimensionHeight toSize:40];
    
    AppButtonView* companyView = [AppButtonView newAutoLayoutView];
    [self.view addSubview:companyView];
    companyView.tag = 3;
    companyView.delegate       = self;
    [companyView setLeftText:@"公司"];
    [companyView setRightText:@"国际贸易唬逼有限公司"];
    [companyView hiddenLine];
    [companyView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:sexView withOffset:0];
    [companyView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [companyView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [companyView autoSetDimension:ALDimensionHeight toSize:40];
    
    
    AppButtonView* phoneView = [AppButtonView newAutoLayoutView];
    phoneView.delegate       = self;
    phoneView.tag = 4;
    [self.view addSubview:phoneView];
    [phoneView setLeftText:@"电话"];
    [phoneView setRightText:@"13803140978"];
    [phoneView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:companyView withOffset:15];
    [phoneView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [phoneView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [phoneView autoSetDimension:ALDimensionHeight toSize:40];
    
    AppButtonView* emailView = [AppButtonView newAutoLayoutView];
    emailView.tag = 5;
    emailView.delegate       = self;
    [self.view addSubview:emailView];
    [emailView setLeftText:@"邮箱"];
    [emailView setRightText:@"575801327@qq.com"];
    [emailView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:phoneView withOffset:0];
    [emailView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [emailView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [emailView autoSetDimension:ALDimensionHeight toSize:40];
    
    AppButtonView* QQlView = [AppButtonView newAutoLayoutView];
    QQlView.tag = 6;
    QQlView.delegate       = self;
    [self.view addSubview:QQlView];
    [QQlView setLeftText:@"QQ"];
    [QQlView setRightText:@"575801327"];
    [QQlView hiddenLine];
    [QQlView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:emailView withOffset:0];
    [QQlView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [QQlView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [QQlView autoSetDimension:ALDimensionHeight toSize:40];
    
    
    
}

-(void)onTapButton:(NSMutableDictionary *)_dic
{
    if ([[_dic valueForKey:@"tag"] integerValue]==2)
    {
       AppSexView* sexView = [AppSexView newAutoLayoutView];
        sexView.delegate = self;
        [self.view addSubview:sexView];
        [sexView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
        
        
    }else{
    
    APPTextController* controller = [[APPTextController alloc] initWith:20 minNumber:1 tag:[_dic valueForKey:@"tag"] title:[_dic valueForKey:@"left"] text:[_dic valueForKey:@"right"]];
    controller.delegate = self;
    [self.navigationController pushViewController:controller animated:YES];
    }
}

-(void) onTapSelectSex:(NSString *)sex
{
    AppButtonView * button = (AppButtonView*)[self.view viewWithTag:2];
    [button setRightText:sex];
    
}
-(void)textViewString:(NSString*)tag text:(NSString *)text
{
    NSInteger tagInteger = [ tag integerValue];
 
    AppButtonView* button = (AppButtonView*)[self.view viewWithTag:tagInteger];
   
    [button setRightText:text];
}
-(void)selectImage:(UIButton*)button
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picker animated:YES completion:nil];
    
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    [picker dismissViewControllerAnimated:YES completion:NULL];
    imageView.image = chosenImage;
    
}

- (void)viewWillAppear:(BOOL)animated {
    
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:NO];
    [super viewWillAppear:animated];
    
    
}


- (void)viewWillDisappear:(BOOL)animated {
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
